package org.netEase.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.netEase.dao.commentDao;
import org.netEase.entity.yonghu;
import org.netEase.entity.comment;
import org.netEase.entity.shangping;
import org.netEase.entity.yonghu;
import org.netEase.util.BaseDao;



public class commentDaoImple extends BaseDao implements commentDao {

	@Override
	public List<comment> getbyDate(String d) {
		List<comment> list = new ArrayList<>();
		String sql = "SELECT c.id,z.namesp,c.com_images,c.Com_date,c.com_content,c.com_praise,sh.Sname,sh.Sjiage FROM COMMENT c INNER JOIN zhanghu z ON c.yid=z.hid INNER JOIN shangping sh ON c.sid=sh.sid WHERE c.Com_date LIKE concat(?,'%')";
		ResultSet rs = super.executeQuery(sql, d);
		try {
			while(rs.next()) {
				comment comment = new comment();
				comment.setId(rs.getInt("id"));
				yonghu yonghu = new yonghu();
				yonghu.setNamesp(rs.getString("namesp"));
				comment.setYonghu(yonghu);
				comment.setCom_images(rs.getString("com_images"));
				comment.setCom_content(rs.getString("com_content"));
				comment.setCom_date(rs.getTimestamp("com_date"));
				comment.setCom_praise(rs.getString("com_praise"));
				shangping shangping = new shangping();
				shangping.setShopname(rs.getString("sname"));
				shangping.setSjiage(rs.getDouble("Sjiage"));
				comment.setShangping(shangping);
				
				list.add(comment);
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				closeAll(rs.getStatement().getConnection(), rs.getStatement(), rs);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return list;
	}

	@Override
	public List<comment> getbyDate() {
		List<comment> list = new ArrayList<>();
		String sql = "SELECT c.id,z.namesp,c.com_images,c.Com_date,c.com_content,c.com_praise FROM  COMMENT c INNER JOIN zhanghu z ON c.yid=z.hid  ";
		ResultSet rs = super.executeQuery(sql);
		try {
			while(rs.next()) {
				comment comment = new comment();
				comment.setId(rs.getInt("id"));
				comment.setCom_images(rs.getString("com_images"));
				comment.setCom_content(rs.getString("com_content"));
				comment.setCom_date(rs.getTimestamp("com_date"));
				comment.setCom_praise(rs.getString("com_praise"));
				yonghu yonghu = new yonghu();
				yonghu.setNamesp(rs.getString("namesp"));
				comment.setYonghu(yonghu);
				list.add(comment);
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				closeAll(rs.getStatement().getConnection(), rs.getStatement(), rs);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return list;
	}
	
}
